package com.foreknow.demo10;

import java.io.*;

public class TestEmployee {
    public static void main(String[] args) {
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream("t.tmp");
            ObjectOutputStream oos = new ObjectOutputStream(fos);
            //向文件中写对象
            oos.writeObject(new Employee("张三",20,"市场部"));
            oos.writeObject(new Employee("李四",21,"市场部"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        FileInputStream fis  = null;
        try {
            fis = new FileInputStream("t.tmp");
            ObjectInputStream ois = new ObjectInputStream(fis);
            Employee e1 = (Employee) ois.readObject();
            Employee e2 = (Employee) ois.readObject();
            System.out.println(e1.getName());
            System.out.println(e2.getName());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }


    }
}
